package cn.kdlc.demo.retrofit;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView textView;

    private MainPresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        presenter = new MainPresenter();
        textView = (TextView) findViewById(R.id.activity_main_state);
    }

    @Override
    protected void onStart() {
        super.onStart();
        if (presenter != null) {
            presenter.bind(this);
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (presenter != null) {
            presenter.unBind();
        }
    }

    public void loadData(View v) {
        if (presenter != null) {
            presenter.loadData();
        }
    }

    public void updateView(String data) {
        textView.setText(data);
    }
}
